#pragma once 

#include <iostream>
#include <stdarg.h>
#include <time.h>

#define INFO 1
#define DEBUG 2
#define ERROR 3
#define WARNING 4
#define FATAL 5

const char* level_arr[] = {
    "INFO",
    "DEBUG",
    "ERROR",
    "WARNING",
    "FATAL"
};

void log(int level, const char* format, ...)
{
    time_t cur_time = time(nullptr);
    struct tm* cur = localtime(&cur_time);
    char stdbuff[1024];
    snprintf(stdbuff, sizeof(stdbuff), "[%s][%d-%d-%d %d:%d:%d]", level_arr[level - 1], cur->tm_year + 1900, \
                cur->tm_mon + 1, cur->tm_mday, cur->tm_hour, cur->tm_min, cur->tm_sec);

    char selfbuffer[1024];
    va_list s;
    va_start(s, format);
    vsnprintf(selfbuffer, sizeof(selfbuffer), format, s);
    va_end(s);

    char buffer[1024*2];
    snprintf(buffer, sizeof(buffer), "%s %s", stdbuff, selfbuffer);

    printf("%s\n", buffer);
}